package com.baihan.angus.app.game.busshow.adps;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.busshow.R;

public class ScriptDialogTitleAdp extends BaseAdp<String, ScriptDialogTitleAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;
    private int thisPosition;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_script_menu, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;

        String title = getItem(position);

        if (!TextUtils.isEmpty(title)) {
            vh.tvMenu.setText(title);
        }

        if (position == getthisPosition()) {
            vh.tvMenu.setTextColor(BaseApplication.getApplication().getColor(R.color.appColor));
            vh.ivCheck.setVisibility(View.VISIBLE);
        } else {
            vh.tvMenu.setTextColor(BaseApplication.getApplication().getColor(R.color.bg4));
            vh.ivCheck.setVisibility(View.GONE);
        }

        vh.llItem.setOnClickListener(view -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public int getthisPosition() {
        return thisPosition;
    }

    public void setThisPosition(int thisPosition) {
        this.thisPosition = thisPosition;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView ivCheck;
        TextView tvMenu;
        LinearLayout llItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivCheck = itemView.findViewById(R.id.ivCheck);
            tvMenu = itemView.findViewById(R.id.tvMenu);
            llItem = itemView.findViewById(R.id.llItem);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
